package com.apes.fn.rpt.profit.grossProfitProcess.processor;

import com.apes.fn.rpt.profit.grossProfitProcess.CommonGrossProfitProcess;
import com.apes.fn.rpt.profit.grossProfitProcess.GrossProfitProcess;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 会员联盟结算-支出
 */
@Component
public class VipUnionOutExpense extends CommonGrossProfitProcess implements GrossProfitProcess {

    @Override
    public String getSQL(Date taskDate){

        return " SELECT TRUNC(X.CREATE_DATE)                      CREATE_DATE, " +
                "       '预收'                                      INCOME_CATEGORIES, " +
                "       '会员联盟结算-支出'                               SERVE_TYPE_NAME, " +
                "       X.DEPT_ID, " +
                "       X.COMPANY_ID, " +
                "       SUM(X.AMOUNT)                             AMOUNT, " +
                "       0                                         TIMES, " +
                "       SUM(X.AMOUNT)                             PRICE_TOTAL, " +
                "       0                                         COST, " +
                "       0                                         CONSUMABLE_USE, " +
                "       0                                         ACCESSORY_COST," +
                "0 vip_in,0 vip_out, " +
                "       0                                         MAN_HOUR_COST, " +
                "       SUM(X.PLATFORM_MANAGEMENT_FEE)            PLATFORM_MANAGEMENT_FEE, " +
                "       0                                         SUPPLY_CHAIN_MANAGEMENT_FEE" +
                " FROM (SELECT TRUNC(A.STATISTIC_DATE)  CREATE_DATE, " +
                "             A.settlement_amount AMOUNT, " +
                "             A.DEPT_ID, " +
                "             A.COMPANY_ID, " +
                "             PLATFORM_MANAGEMENT_FEE " +
                "      from vip_union_report A " +
                "      where A.type = 'out' " +
                "        and DEPT_ID is not null " +
                "        AND A.STATISTIC_DATE >= to_date(:P_DATE, 'YYYY-mm-dd') " +
                "        AND A.STATISTIC_DATE < to_date(:P_DATE, 'YYYY-mm-dd') + 1) X " +
                " GROUP BY X.CREATE_DATE, X.DEPT_ID, " +
                "         X.COMPANY_ID";
    }

    @Override
    public boolean support(String type) {
        return "VipUnionOut".equals(type);
    }
}
